package com.glp.work.flow.contract.builder;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.apache.poi.xwpf.usermodel.XWPFDocument;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ContractSource implements Serializable, Cloneable {

  private String id;
  private String code;
  private String name;
  private String template;

  private List<Mark> marks;

  public XWPFDocument buildDocument() {
    try {
      return new XWPFDocument(ContractSource.class.getResourceAsStream(template));
    } catch (Exception ex) {
      log.error("Faild to build contract document from template. Template is " + template, ex);
      throw new RuntimeException(ex);
    }
  }
  
  @Override
  public ContractSource clone() {
    ContractSource source = new ContractSource();
    source.id = this.id;
    source.code = this.code;
    source.name = this.name;
    source.template = this.template;
    List<Mark> list = new ArrayList<Mark>(this.marks.size());
    for(Mark mark : marks) {
      list.add(mark.clone());
    }
    source.marks = list;
    return source;
  }
  
  public String getId() {
    return id;
  }

  public void setId(String id) {
    this.id = id;
  }

  public String getCode() {
    return code;
  }

  public void setCode(String code) {
    this.code = code;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getTemplate() {
    return template;
  }

  public void setTemplate(String template) {
    this.template = template;
  }

  public List<Mark> getMarks() {
    return marks;
  }

  public void setMarks(List<Mark> marks) {
    this.marks = marks;
  }

}
